import vtkActor from "@kitware/vtk.js/Rendering/Core/Actor";
import { BActor } from "../Core/BActor";
import { ACTOR_TYPE } from "../";
//@ts-ignore
import vtkPolyDataReader from "@kitware/vtk.js/IO/Legacy/PolyDataReader.js";
import vtkMapper from "@kitware/vtk.js/Rendering/Core/Mapper";

export class VtkActor extends BActor {
  readonly type = ACTOR_TYPE.GRAPHIC_ACTOR;
  createdBy = "default";
  instance: vtkActor = vtkActor.newInstance();
  mapper: vtkMapper = vtkMapper.newInstance({ scalarVisibility: false });
  reader: vtkPolyDataReader = vtkPolyDataReader.newInstance();
  constructor(url: string) {
    super();
    this.reader.setUrl(url, {
      binary: true,
    })
      .then(() => {
        this.instance.setMapper(this.mapper);
        this.reader.loadData();
        const polydata = this.reader.getOutputData();
        this.mapper.setInputData(polydata);
      })
      .catch((error) => {
        console.error('Failed to load model:', error);
      });
    
  }
}
